package com.example.controller.multisource;

import com.example.pojo.entity.multisource.User;
import com.example.mapper.test1.User1Mapper;
import com.example.mapper.test2.User2Mapper;
import com.example.pojo.vo.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2020/9/26 15:17
 */
@RestController
@Slf4j
public class UserController {
    @Autowired
    private User1Mapper user1Mapper;

    @Autowired
    private User2Mapper user2Mapper;

    @RequestMapping("/getUsers")
    public Result getUsers() {
        List<User> user1=user1Mapper.getAll();
        user1.forEach(val->{
            log.info("user1:{}",val.toString());
        });

        List<User> user2=user2Mapper.getAll();
        user2.forEach(val->{
            log.info("user2:{}",val.toString());
        });

        return Result.OK();
    }

    @RequestMapping("/getUser")
    public User getUser(Long id) {
        User user=user2Mapper.getOne(id);
        return user;
    }

    @RequestMapping("/add")
    public void save(User user) {
        user2Mapper.insert(user);
    }

    @RequestMapping(value="update")
    public void update(User user) {
        user2Mapper.update(user);
    }

    @RequestMapping(value="/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        user1Mapper.delete(id);
    }

}
